package com.boat.sample.ddd.infrastructure.persistence.factory;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

import org.springframework.stereotype.Component;

import com.boat.sample.ddd.domain.system.entity.LoginLog;
import com.boat.sample.ddd.infrastructure.persistence.po.LoginLogPo;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import lombok.extern.slf4j.Slf4j;

/**
 * LoginLog工厂类
 * @author noia_zhou
 *
 */
@Slf4j
@Component
public class LoginLogFactory {
	public LoginLog buildLoginLog(LoginLogPo loginLogPo) {
		if (loginLogPo == null) {
			return null;
		}

		LoginLog loginLog = new LoginLog();
		BeanUtil.copyProperties(loginLogPo, loginLog, CopyOptions.create().ignoreError());
		return loginLog;
	}

	public LoginLogPo buildLoginLogPo(LoginLog loginLog) {
		if (loginLog == null) {
			return null;
		}

		LoginLogPo loginLogPo = new LoginLogPo();
		BeanUtil.copyProperties(loginLog, loginLogPo, CopyOptions.create().ignoreError());
		return loginLogPo;
	}

	public List<LoginLogPo> buildLoginLogPoList(Collection<LoginLog> loginLogList) {
		if (loginLogList == null) {
			return null;
		}
		
		return loginLogList.stream().map(loginLog -> buildLoginLogPo(loginLog)).collect(Collectors.toList());
	}

	public List<LoginLog> buildLoginLogList(Collection<LoginLogPo> poList) {
		if (poList == null) {
			return null;
		}
		
		return poList.stream().map(loginLogPo -> buildLoginLog(loginLogPo)).collect(Collectors.toList());
	}
    
	public LoginLogPo buildDeleteLoginLogPo(String id) {
		if (id == null) {
			return null;
		}

		LoginLogPo loginLogPo = new LoginLogPo();
		loginLogPo.setId(id);
		loginLogPo.setDeleted(Long.valueOf(System.currentTimeMillis()/1000).intValue());
		return loginLogPo;
	}
}
